package com.san.hkhospital.service.impl;

import com.san.hkhospital.vo.EmpTableVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.san.hkhospital.entity.EmployeeExample;
import com.san.hkhospital.mapper.EmployeeMapper;
import com.san.hkhospital.entity.Employee;
import com.san.hkhospital.service.EmployeeService;
import org.springframework.transaction.annotation.Transactional;

/**
 * ClassName:EmployeeServiceImpl
 * PackageName:com.san.hkhospital.service.impl
 * Description:
 *
 * @Author:yy
 * @CreatedAt:2024/11/13 14:38
 * 
 */
 
 
@Service
@Transactional
public class EmployeeServiceImpl implements EmployeeService{

    @Resource
    private EmployeeMapper employeeMapper;

    @Override
    public long countByExample(EmployeeExample example) {
        return employeeMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(EmployeeExample example) {
        return employeeMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer empId) {
        return employeeMapper.deleteByPrimaryKey(empId);
    }

    @Override
    public int insert(Employee record) {
        return employeeMapper.insert(record);
    }

    @Override
    public int insertSelective(Employee record) {
        return employeeMapper.insertSelective(record);
    }

    @Override
    public List<Employee> selectByExample(EmployeeExample example) {
        return employeeMapper.selectByExample(example);
    }

    @Override
    public Employee selectByPrimaryKey(Integer empId) {
        return employeeMapper.selectByPrimaryKey(empId);
    }

    @Override
    public int updateByExampleSelective(Employee record,EmployeeExample example) {
        return employeeMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByExample(Employee record,EmployeeExample example) {
        return employeeMapper.updateByExample(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(Employee record) {
        return employeeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Employee record) {
        return employeeMapper.updateByPrimaryKey(record);
    }




    //*************************************************************************
    //员工添加方法

    @Override
    public boolean employeeAdd(Employee employee) {
        EmployeeExample example = new EmployeeExample();
        example.createCriteria().andEmpIdcardEqualTo(employee.getEmpIdcard());
        List<Employee> existingEmployees = employeeMapper.selectByExample(example);

        if (!existingEmployees.isEmpty()) {
            return false;
        }

        int rowsAffected = employeeMapper.insert(employee);
        return rowsAffected > 0;
    }
    //员工删除方法
    @Override
    public boolean deleteemploy(Integer empId) {
        return employeeMapper.deleteByPrimaryKey(empId)>0?true:false;
    }
    //员工状态修改
    @Override
    public boolean changeUstate(Integer empId, Integer stateId) {
        Employee employee = new Employee();
        employee.setEmpId(empId);
        employee.setStateId(stateId);
        int i = employeeMapper.updateByPrimaryKeySelective(employee);
        return i>0?true:false;
    }
    //员工全部修改
    @Override
    public int updateemploy(Employee employee) {
        return employeeMapper.updateByPrimaryKey(employee);
    }

    //员工查询
    @Override
    public List<Employee> selectEmployee() {
        return employeeMapper.selectByExample(null);
    }

    //员工查询vo
    @Override
    public List<EmpTableVo> selectEmployeeVo() {

        return employeeMapper.selectAll();
    }


    //搜索查询
    @Override
    public List<Employee> searchList(Map<String, String> params) {
        return employeeMapper.searchEmployee(params);
    }

    public List<Employee> selectAllDoct() {
        EmployeeExample example =new EmployeeExample();
        example.createCriteria().andPositionIdEqualTo(1);
        return employeeMapper.selectByExample(example);
    }

    //搜索查询
//    @Override
//    public List<Employee> searchList(Map<String, String> params) {
//        return employeeMapper.searchEmployee(params);
//    }

}
